#pragma once
#include <Windows.h>
#include <map>

#define DECLARE_MSG_MAP \
friend class _EventCreator;

#define BEGIN_MSG_MAP(_class)                                        \
typedef LRESULT (_class::*MsgFn)(WPARAM, LPARAM);                    \
typedef _class _TheClass;                                            \
class _EventCreator {                                                \
    std::map<UINT, MsgFn> _msgMap;                                   \
public:                                                              \
   LRESULT call(_class* obj, UINT msg, WPARAM w, LPARAM l) {         \
        std::map<UINT, MsgFn>::iterator iter = _msgMap.find(msg);    \
        if (iter != _msgMap.end()) {                                 \
            return (obj->*(iter->second))(w, l);                     \
        }                                                            \
        return FALSE;                                                \
   }                                                                 \
    _EventCreator() {                                               

#define ON_MSG(msg, fn) \
_msgMap.insert(make_pair(msg, (MsgFn)&_TheClass::fn));

#define END_MSG_MAP     \
    }                   \
} EVENT_HANDLER;    